package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JWindow;
import competitionImpl.MatchImpl;

public class actionAfficherMatchs extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6243339099086167442L;
	private List<MatchImpl> listMatchs;

	
	
	public actionAfficherMatchs(List<MatchImpl> matchs) {
		super();
		this.listMatchs = matchs;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		this.setTitle("Matchs");
		this.setSize(500, 600);
		this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); //fermeture lors du clic sur la croix
		setLocationRelativeTo(null);
		JPanel panel = new JPanel();
		this.setContentPane(panel);
		
		String[] columns = {"Vainqueur", "Perdant"};
		
		JTable tableMatch = new JTable(this.getTabMatchs(), columns);
		tableMatch.setSize(500, 600);
		JScrollPane scrollPan = new JScrollPane(tableMatch);
		scrollPan.setSize(500, 600);
		
		
		this.getContentPane().add(tableMatch.getTableHeader() );
		this.getContentPane().add( scrollPan);
		
		this.setVisible(true);
	}

	private Object[][] getTabMatchs() {

		Object[][] tabData = null;
		int size = this.listMatchs.size();
		int i = 0;
		
		tabData = new Object[size][2];
		
		for (MatchImpl match : this.listMatchs) {
			if(match != null){
			tabData[i][0] = match.getVainqueur().getNom();
			tabData[i][1] = match.getPerdant().getNom();
			}
			i++;
		}
		
		return tabData;
	}

	public void setMatchs(List<MatchImpl> matchs) {
		this.listMatchs = matchs;
		
	}

}
